﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace StandUp.userControls
{
    public partial class SingleEvents : UserControl
    {
        public SingleEvents()
        {
            InitializeComponent();
        }
        private int id=-1;
        private string unique="";
        /// <summary>
        /// 事件ID
        /// </summary>
        public int ID
        {
            get { return id; }
            set { id = value; }
        }
        /// <summary>
        /// 事件唯一标识
        /// </summary>
        public string Unique
        {
            get { return unique; }
            set { unique = value; }
        }
        AssData.DataSelect Mybll = new AssData.DataSelect();
        AssData.EventModel Model = new AssData.EventModel();
        private void DayOfEvents_Load(object sender, EventArgs e)
        {
            if (id != -1 || unique != "")
            {
                flowLayoutPanel1.Visible = false;
                Model = Mybll.GetEventByID(id, unique);
                setInfo(Model);
            }
        }
        /// <summary>
        /// 获取事件信息
        /// </summary>
        /// <param name="model"></param>
        void setInfo(AssData.EventModel model)
        {
            lb_date.Text = model.Startime.ToString("MM月dd日");
            lb_stime.Text = model.Startime.ToString("HH:mm");
            if (model.Startime.Year != model.Endtime.Year)
                lb_etime.Text = model.Endtime.ToString("~yyyy/MM/dd HH:mm");
            else
                lb_etime.Text = (model.Startime.DayOfYear == model.Endtime.DayOfYear ? model.Endtime.ToString("~HH:mm") : model.Endtime.ToString("~MM/dd HH:mm"));
            lb_title.Text = model.EventTitle;
            lb_location.Text = model.EventLocation;
            lb_mark.Text = model.EventMark;
            lb_id.Text = model.ID.ToString();
        }

        private void lb_del_Click(object sender, EventArgs e)
        {
            flowLayoutPanel1.Visible = !flowLayoutPanel1.Visible;
        }
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lb_delevent_Click(object sender, EventArgs e)
        {
            Mybll.DelEvent(int.Parse(lb_id.Text), "-1");
            this.Visible = false;
        }

        private void lb_title_Click(object sender, EventArgs e)
        {
            AddEvent add = new AddEvent(int.Parse(lb_id.Text));
            add.ShowDialog();
        }

        private void lb_stop_Click(object sender, EventArgs e)
        {
            
        }

        private void lb_end_Click(object sender, EventArgs e)
        {

        }
    }
}
